/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author antonio
 */
@Entity
@Table(name = "Production")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Production.findAll", query = "SELECT p FROM Production p"),
    @NamedQuery(name = "Production.findByResource", query = "SELECT p FROM Production p WHERE p.productionPK.resource = :resource"),
    @NamedQuery(name = "Production.findByAmount", query = "SELECT p FROM Production p WHERE p.amount = :amount")})
public class Production implements Serializable {

    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ProductionPK productionPK;
    @Basic(optional = false)
    @NotNull
    @Column(name = "amount")
    private int amount;
    @JoinColumn(name = "construct", referencedColumnName = "name", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Construct construct1;
    @JoinColumn(name = "resource", referencedColumnName = "name", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Resource resource1;

    public Production() {
    }

    public Production(ProductionPK productionPK) {
        this.productionPK = productionPK;
    }

    public Production(ProductionPK productionPK, int amount) {
        this.productionPK = productionPK;
        this.amount = amount;
    }

    public Production(String resource, String build) {
        this.productionPK = new ProductionPK(resource, build);
    }

    public ProductionPK getProductionPK() {
        return productionPK;
    }

    public void setProductionPK(ProductionPK productionPK) {
        this.productionPK = productionPK;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    public Construct getConstruct1() {
        return construct1;
    }

    public void setConstruct1(Construct construct1) {
        this.construct1 = construct1;
    }

    public Resource getResource1() {
        return resource1;
    }

    public void setResource1(Resource resource1) {
        this.resource1 = resource1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (productionPK != null ? productionPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Production)) {
            return false;
        }
        Production other = (Production) object;
        if ((this.productionPK == null && other.productionPK != null) || (this.productionPK != null && !this.productionPK.equals(other.productionPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Production[ productionPK=" + productionPK + " ]";
    }
    
}
